package cn.boat.router.utils;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 在原子类的基础上，增添两个特性
 * 1. 非负
 * 2. 不超过Integer最大值
 */
public class PositiveAtomicCounter {
    private AtomicInteger atom = new AtomicInteger(0);
    private static int mask = Integer.MAX_VALUE;

    public PositiveAtomicCounter() {
    }

    public final int incrementAndGet() {
        int rt = this.atom.incrementAndGet();
        return rt & mask;
    }

    public int intValue() {
        return this.atom.intValue();
    }
}
